<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%--
  Created by IntelliJ IDEA.
  User: 和
  Date: 2020/10/21
  Time: 8:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  request.setCharacterEncoding("utf-8");
  String username =request.getParameter("username");
  String password =request.getParameter("password");
  //加载驱动
  Class.forName("com.mysql.jdbc.Driver");

//建立数据库连接
  String url="jdbc:mysql://localhost:3306/book";//数据库连接地址
  Connection connection=DriverManager.getConnection(url,"root","root");

  //sql模板
  String sql = "select * from user where username = ? and password = ?";
  //使用PreparedStatement对象执行sql语句
  PreparedStatement PS = connection.prepareStatement(sql);

  ps.setString(1,username);
  ps.setString(2,password);

  PesultSet rs =ps.executeQuery();

  if (rs.next()){
    out.print("登录成功");
    response.sendRedirect("home.jsp");
  }else{
    out.print("登录失败");
    response.sendRedirect("login.jsp");
  }
%>